from selenium import webdriver
from time import sleep


chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')

#1.创建Chrome浏览器对象，这会在电脑上在打开一个浏览器窗口
browser = webdriver.Chrome(chrome_options=chrome_options,executable_path ="D:\program\chromedriver.exe")
print("浏览器加载完成!")

#2.通过浏览器向服务器发送URL请求
browser.get("https://www.fdcff5a2176f.com//tupian/150972.html")

#sleep(15)
#滚动到最下面
#browser.execute_script("window.scrollTo(0,document.body.scrollHeight);")
#sleep(15)
images=browser.find_elements_by_class_name('videopic')
couts= len(images)
print(couts)
for image in images:
    print(image.get_attribute("src"))
    #browser.execute_script("window.scrollTo(0,document.body.scrollHeight);")
    # 滑动滚动条到某个指定的元素
    js4 = "arguments[0].scrollIntoView();"
    # 将下拉滑动条滑动到当前div区域
    browser.execute_script(js4, image)

#3.刷新浏览器
#browser.refresh()
sleep(5)
print("=================================")
images_2=browser.find_elements_by_class_name('videopic')
for image in images_2:

    print(image.get_attribute("src"))